<template>
  <div id="app">
    <div class="header">
      <a class="home" href="javascript:;">
        <img src="../assets/jdxiaofangzi.png" alt="" />
      </a>
      <input
        type="text"
        @keyup="jianpan"
        v-model="val"
        placeholder="搜索本店商品"
      />
      <i class="seach"> </i>
      <a class="List" href="javascript:;">
        <img src="../assets/jdddd.png" alt="" />
      </a>
    </div>
    <div class="navda">
      <ul class="nav">
        <li>
          <a class="yanse" href="javascript:;">默认</a>
        </li>
        <li>
          <a @click="xiaoliang" href="javascript:;">销量</a>
        </li>
        <li>
          <a @click="jiage" href="javascript:;">价格</a>
        </li>
        <li>
          <a @click="shijian" href="javascript:;">上新</a>
        </li>
      </ul>
      <a @click="huan" class="qiehuan" href="javascript:;"> </a>
    </div>
    <main>
      <ul class="commodity">
        <li
          v-bind:style="{ width: width1 + '%' }"
          v-for="(value, index) in arr"
          :key="index"
        >
          <img class="tupian" :src="value.pic1" alt="" />
          <p class="wenzi">{{ value.title }}</p>
          <span class="jiaqian">{{ value.price }}￥</span>
          <span class="manjian" v-if="value.manjian">满减</span>
          <p class="wz">
            <span class="xiaoliang">{{ value.xiaoliang }}+</span>
            <span class="haoping">好评率:{{ value.pj }}%</span>
          </p>
        </li>
      </ul>
    </main>
  </div>
</template>
<style>
.nav li .yanse {
  color: #ff5500;
  border-bottom: 1px solid #ff5500;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.wz {
  margin-top: 0.1rem;
  padding-left: 0.1rem;
}
.haoping {
  font-size: 0.18rem;
  color: #ccc;
  margin-top: 0.1rem;
  margin-left: 0.1rem;
}
.xiaoliang {
  font-size: 0.2rem;
  margin-top: 0.1rem;
  color: #ccc;
}
.commodity {
  float: left;
  width: 100%;
  overflow: hidden;
  font-size: 0.3rem;
}
.commodity li {
  float: left;
  width: 44%;
  height: 4rem;
  padding-top: 0.2rem;
  margin-left: 0.3rem;
  margin-top: 0.3rem;
  background: #fff;
  box-sizing: border-box;
  border-radius: 0.1rem;
}

.tupian {
  width: 100%;
  height: 2rem;
  border-radius: 0.1rem;
}
.wenzi {
  width: 100%;
  height: 0.7rem;
  line-height: 0.36rem;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin-bottom: 0.1rem;
  padding-left: 0.1rem;
}
.jiaqian {
  font-size: 0.24rem;
  color: #ff5500;
  padding-left: 0.1rem;
}
.manjian {
  width: 0.8rem;
  text-align: center;
  color: #ff5500;
  border: 1px solid #ff5500;
  display: inline-block;
  font-size: 0.26rem;
  padding-left: 0.1rem;
}
* {
  margin: 0;
  padding: 0;
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  line-height: 1;
}
a {
  text-decoration: none;
}
ul,
li {
  list-style: none;
}

a,
input,
button {
  -webkit-tap-highlight-color: transparent;
  /* 移除点击产生的高亮效果：透明色 */
}
input,
button {
  -webkit-appearance: none;
  /* 在ios中加入这句能修改button和input的宽高 */
}
img,
a {
  -webkit-touch-callout: none;
  /* 禁止长按弹出菜单 */
}
img {
  vertical-align: middle;
}
li {
  list-style: none;
}
#app {
  display: flex;
  flex-direction: column;
}
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  height: 1rem;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f1f1f1;
  background: #fff;
}
.navda {
  width: 100%;
  position: fixed;
  top: 1rem;
  left: 0;
  background: #fff;
}
.header input {
  width: 4.4rem;
  height: 0.58rem;
  border-radius: 6px;
  outline: none;
  border: none;
  background: #f7f7f7;
  padding-left: 0.8rem;
  box-sizing: border-box;
}
.home {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-left: 0.2rem;
}
.home img {
  height: 0.4rem;
  width: 0.5rem;
}
main {
  flex: 1;
  margin-top: 2rem;
  background: #f5f5f5;
}
.seach {
  position: absolute;
  left: 26%;
  width: 0.3rem;
  height: 0.3rem;
  background: url(../assets/jdseach.png) no-repeat;
  background-size: 100% 100%;
}
.List {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-right: 0.2rem;
}
.List img {
  height: 0.1rem;
  width: 0.5rem;
}
.nav {
  float: left;
  width: 80%;
  height: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 0.3rem;
  padding-right: 0.3rem;
}
.nav li {
  font-size: 0.28rem;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}
.nav li a {
  color: #000;
}
.qiehuan {
  margin-top: 0.1rem;
  width: 0.8rem;
  height: 0.8rem;
  float: left;
  background: url(../assets/jdqiehuan.png);
  margin-left: 0.3rem;
}
</style>
<script>
export default {
  data() {
    return {
      arr: [
        {
          title:
            "西铁城(CITIZEN)男士腕表 光动能小蓝针小牛皮表带时尚休闲生活防水商务手表 AO9000-06B七夕情人节礼物 送男友送老公",
          price: 1282,
          pic1: require("../assets/jdsb1.png"),
          manjian: "true",
          pj: "100%",
          xiaoliang: 2000,
          time: 1,
        },
        {
          title:
            "西铁城(CITIZEN)女士手表 光动能机芯不锈钢表带休闲时尚防水手表EW2530-87A七夕情人节礼物 送女友送老婆",
          price: 1131,
          pic1: require("../assets/jdsb2.jpg"),
          manjian: "false",
          pj: "100%",
          xiaoliang: 500,
          time: 2,
        },
        {
          title:
            "西铁城(CITIZEN)女士腕表 礼盒款 光动能满天星时尚休闲商务防水手表EM0770-52Y七夕情人节礼物 送女友送老婆",
          price: 1634,
          pic1: require("../assets/jdsb3.jpg"),
          manjian: "",
          pj: "78%",
          xiaoliang: 500,
          time: 3,
        },
        {
          title:
            "西铁城(CITIZEN)男士腕表 礼盒款光动能不锈钢表带绿水鬼表盘游泳防水商务手表 AW1598-70X七夕情人节礼物 送男友送老公",
          price: 1613,
          pic1: require("../assets/jdsb4.jpg"),
          manjian: "false",
          pj: "71%",
          xiaoliang: 2000,
          time: 4,
        },
        {
          title:
            "西铁城(CITIZEN)男士腕表 光动能电波钛金属运动/时尚防水手表JY8100-80E",
          price: 4899,
          pic1: require("../assets/jdsb5.jpg"),
          manjian: "true",
          pj: "91%",
          xiaoliang: 200,
          time: 5,
        },
        {
          title:
            "西铁城(CITIZEN)男士手表 机械机芯不锈钢表带休闲时尚防水手表NH8350-59A",
          price: 1140,
          pic1: require("../assets/jdsb6.jpg"),
          manjian: "true",
          pj: "94%",
          xiaoliang: 200,
          time: 6,
        },
        {
          title:
            "西铁城(CITIZEN)女士腕表 光动能水晶手链表带简约时尚生活防水手表 EX1420-50E七夕情人节礼物 送女友送老婆",
          price: 1329,
          pic1: require("../assets/jdsb7.jpg"),
          manjian: "true",
          pj: "76%",
          xiaoliang: 200,
          time: 7,
        },
        {
          title:
            "西铁城(CITIZEN)女士手表 光动能机芯不锈钢表带休闲时尚防水手表EW2540-83L",
          price: 1440,
          pic1: require("../assets/jdsb8.jpg"),
          manjian: "true",
          pj: "84%",
          xiaoliang: 200,
          time: 8,
        },
      ],
      val: "",
      arrNew: [],
      width1: 44,
      n: 0,
    };
  },
  methods: {
    jianpan(e) {
      this.arrNew = [];
      if (e.keyCode == 13) {
        this.arr.forEach((i) => {
          console.log(i.title);
          if (i.title.indexOf(this.val) != -1) {
            this.arrNew.push(i);
          }
        });
        this.arr = this.arrNew;
        this.arrNew = [];
      }
    },
    huan() {
      this.n++;
      if (this.n % 2 == 0) {
        this.width1 = 44;
      } else {
        this.width1 = 88;
      }
    },
    xiaoliang() {
      this.arr.forEach((indes) => {
        this.arr.sort(function (a, b) {
          return b.xiaoliang - a.xiaoliang;
        });
        this.arr = this.arr;
      });
    },
    jiage() {
      this.arr.forEach((indes) => {
        this.arr.sort(function (a, b) {
          return a.price - b.price ;
        });
        this.arr = this.arr;
      });
    },
        shijian() {
      this.arr.forEach((indes) => {
        this.arr.sort(function (a, b) {
          return b.time - a.time;
        });
        this.arr = this.arr;
      });
    },

  },
};
</script>
